/*****************************************************************************/
/**
*
* @file esp8266.h
*
* Header file for esp8266.c.
* Target device: STM32F103RET6.
* Target board: ONENET kylin v2.3
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver   Who    Date   	Changes
* ----- ---- ---------- -------------------------------------------------------
* 0.01  abu  02/19/2020 Created
* </pre>
*
*------------------------------------------------------------------------------
* Author:	abu
*					E-mail:	abu_liu@opencores.org
*------------------------------------------------------------------------------
*
******************************************************************************/
#ifndef ESP8266_H		/* prevent circular inclusions */
#define ESP8266_H		/* by using protection macros */

#ifdef __cplusplus
	extern "C" {
#endif

/***************************** Include Files *********************************/
#include "stm32f10x.h"
#include "bsp_misc.h"

/************************** Constant Definitions *****************************/
//parameters about ESP8266 usart port
#define ESP8266_USART	USART2
#define ESP8266_USART_BAUD	115200
#define ESP8266_RST_GPIO_PERIPH_PORT	RCC_APB2Periph_GPIOA
#define ESP8266_RST_GPIO_PORT	GPIOA
#define ESP8266_RST_GPIO_PIN	GPIO_Pin_0

#define ESP8266_WriteByte(data)		USART_SendByte(ESP8266_USART,data)
#define ESP8266_WriteString(str)	USART_SendString(ESP8266_USART,str)
#define ESP8266_WriteCmd(str)		USART_SendString(ESP8266_USART,str)

#define ESP8266_DeviceRst()	GPIO_SetBits(ESP8266_RST_GPIO_PORT,ESP8266_RST_GPIO_PIN)
#define ESP8266_DeviceRst()	GPIO_ResetBits(ESP8266_RST_GPIO_PORT,ESP8266_RST_GPIO_PIN)
		
#define ESP8266_RECV_BUFFER_SIZE	256

typedef enum {
	BUFFER_BUSY = 0x01,
	BUFFER_IDLE = 0x02,
	BUFFER_FULL = 0x04,
	BUFFER_EMPTY = 0x08
} Buffer_Status;

typedef struct
{
	Buffer_Status status;		//status of buffer, reserved for future use
	unsigned short dataLen;		//counter of received bytes
	unsigned char buf[ESP8266_RECV_BUFFER_SIZE];		//buffer, 256 bytes
} ESP8266_RECV;

extern ESP8266_RECV ESP8266_Recv_Info;

enum CW_Mode{
	CW_Mode_Station = 1,
	CW_Mode_AP = 2,
	CW_Mode_StationAndAP = 3
};

/************************** Function Declarations ******************************/
void ESP8266_Init(void);
void ESP8266_Clr_Recv_Buffer(void);

#ifdef __cplusplus
}
#endif

#endif
